//
//  TjModel.swift
//  GjCup
//
//  Created by abc on 2024/4/7.
//

import UIKit
enum TjType: Int {
    case km3 = 0
    case m3
    case dm3
    case cm3
    case mm3
    case l
    case dl
    case ml
    case cl
    case hl
    case cuft
    case cuin
    case cuyd
    case muyingchi
    case ukgal
    case usgal
    case ul
    case koz
    case uoz
}

class TjModel: NSObject {
    let types = ["立方千米","立方米","立方分米","立方厘米","立方毫米","升","分升","毫升","厘升","公石","立方英尺","立方英寸","立方码","亩英尺","英制加仑","美制加仑","微升","英制液体盎司","美制液体盎司"]
    let signs = ["km³","m³","dm³","cm³","mm³","l","dl","ml","cl","hl","cu ft","cu in","cu yd","亩英尺","uk gal","us gal","ul","oz","oz"]
    
    
    
    func kmTall(n: Double, type: TjType, reverse: Bool = false) -> Double {
        var km3 = n
        switch type {
        case .km3:
            break
        case .m3:
            km3 = reverse ? n / 1000000000: n * 1000000000
            break
        case .dm3:
            km3 = reverse ? n / 1000000000000: n * 1000000000000
            break
        case .cm3:
            km3 = reverse ? n / 1e+15: n * 1e+15
            break
        case .mm3:
            km3 = reverse ? n / 1e+18: n * 1e+18
            break
        case .l:
            km3 = reverse ? n / 1000000000000: n * 1000000000000
            break
        case .dl:
            km3 = reverse ? n / 10000000000000: n * 10000000000000
            break
        case .ml:
            km3 = reverse ? n / 1e+15: n * 1e+15
            break
        case .cl:
            km3 = reverse ? n / 1e+14: n * 1e+14
            break
        case .hl:
            km3 = reverse ? n / 10000000000: n * 10000000000
            break
        case .cuft:
            km3 = reverse ? n / 35314724827.66: n * 35314724827.66
            break
        case .cuin:
            km3 = reverse ? n / 6.1024e+13: n * 6.1024e+13
            break
        case .cuyd:
            km3 = reverse ? n / 1307952771.395: n * 1307952771.395
            break
        case .muyingchi:
            km3 = reverse ? n / 810713.1937899: n * 810713.1937899
            break
        case .ukgal:
            km3 = reverse ? n / 219969157332.6: n * 219969157332.6
            break
        case .usgal:
            km3 = reverse ? n / 264172052358.1: n * 264172052358.1
            break
        case .ul:
            km3 = reverse ? n / 1e+18: n * 1e+18
            break
        case .koz:
            km3 = reverse ? n / 3.5199e+13: n * 3.5199e+13
            break
        case .uoz:
            km3 = reverse ? n / 3.3818e+13: n * 3.3818e+13
            break
            
        }        
        return km3
    }

    
    func allChange(d: Double, type: TjType) -> [String] {
        let km = kmTall(n: d, type: type, reverse: true)
        
        
        
        return ["\(kmTall(n: km, type: .km3))\(signs[0])","\(kmTall(n: km, type: .m3))\(signs[1])",
                "\(kmTall(n: km, type: .dm3))\(signs[2])","\(kmTall(n: km, type: .cm3))\(signs[3])",
                "\(kmTall(n: km, type: .mm3))\(signs[4])","\(kmTall(n: km, type: .l))\(signs[5])",
                "\(kmTall(n: km, type: .dl))\(signs[6])","\(kmTall(n: km, type: .ml))\(signs[7])","\(kmTall(n: km, type: .cl))\(signs[8])","\(kmTall(n: km, type: .hl))\(signs[9])",
                "\(kmTall(n: km, type: .cuft))\(signs[10])","\(kmTall(n: km, type: .cuin))\(signs[11])",
                "\(kmTall(n: km, type: .cuyd))\(signs[12])","\(kmTall(n: km, type: .muyingchi))\(signs[13])",
                "\(kmTall(n: km, type: .ukgal))\(signs[14])","\(kmTall(n: km, type: .usgal))\(signs[15])",
                "\(kmTall(n: km, type: .ul))\(signs[16])","\(kmTall(n: km, type: .koz))\(signs[17])",
                "\(kmTall(n: km, type: .uoz))\(signs[18])"]

    }

    
}
